/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package old;

import gov.nasa.worldwind.geom.Angle;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layers.MarkerLayer;
import gov.nasa.worldwind.render.DrawContext;
import gov.nasa.worldwind.render.Material;
import gov.nasa.worldwind.render.markers.BasicMarkerAttributes;
import gov.nasa.worldwind.render.markers.BasicMarkerShape;
import gov.nasa.worldwind.render.markers.Marker;
import gov.nasa.worldwind.render.markers.MarkerAttributes;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;
import visualization.GroundData;

/**
 *
 * @author Dark Mark
 */

// klasa reprezentujaca warstwe wierzcholkow
public class SphereMarkerLayer extends MarkerLayer
{
    public SphereMarkerLayer()
    {
    }

    public SphereMarkerLayer(Iterable<Marker> markers)
    {
        super(markers);
    }

    public void draw(DrawContext dc, java.awt.Point pickPoint)
    {
        super.draw(dc, pickPoint);
    }

    public SphereMarkerLayer buildTracksLayer(GroundData gData)
    {
        ArrayList<Marker> markers = new ArrayList<Marker>();

        /*
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 20; j++)
            {
                Position pos = new Position(new LatLon(Angle.fromDegreesLatitude(54.4 + i / 60.0), Angle.fromDegreesLongitude(18.8 + j / 60.0)), new Random().nextInt(2000));
                MarkerAttributes attr = new BasicMarkerAttributes(new Material(Color.ORANGE), BasicMarkerShape.SPHERE, 1, 8, 1);
                markers.add(new SphereMarker(pos, attr));
            }
        }
        */

        for (int i = 0; i < gData.pingsNumber; i++)
        {
            for (int j = 0; j < gData.beamsNumber; j++)
            {
                Position pos = gData.positions[i][j];
                //System.out.println(pos.elevation);
                // obliczenie koloru wierzcholka na podstawie jego wysokosci
                float greenComponent = (float)(Math.abs(pos.elevation-gData.minElevation)/gData.difference);
                if (greenComponent < 0.0f)
                {
                    greenComponent = 0.0f;
                }
                else if (greenComponent > 1.0f)
                {
                    greenComponent = 1.0f;
                }
                // dodanie nowego wierzcholka w postaci markera
                //MarkerAttributes attr = new BasicMarkerAttributes(new Material(Color.ORANGE), BasicMarkerShape.SPHERE, 1, 2, 1);
                MarkerAttributes attr = new BasicMarkerAttributes(new Material(new Color(1.0f, greenComponent, 0.0f)), BasicMarkerShape.SPHERE, 1, 2, 3);
                markers.add(new SphereMarker(pos, attr));
            }
        }

        SphereMarkerLayer layer = new SphereMarkerLayer(markers);
        layer.setOverrideMarkerElevation(false);
        layer.setKeepSeparated(true);
        layer.setElevation(0);

        return layer;
    }
}
